import socket
import sys

serversocket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
host = socket.gethostname()
port = 9999
serversocket.bind((host,port))
serversocket.listen(5)
while True:
    clientsocket,addr = serversocket.accept()
    print('链接地址：%s'% str(addr))
    msg = '欢迎访问菜鸟教程'+'\r\n'
    clientsocket.send(msg.encode('utf-8'))
    while True:
        data = clientsocket.recv(1024)
        if not data:
            print('关闭了一个链接')
            clientsocket.close()
            break
        print(str(data,'utf-8'))
        inp = input('>>>>')
        clientsocket.send(bytes(inp,'utf-8'))
